package storageManager;

import java.io.IOException;
import java.util.Scanner;

public class StorageManager {

	public static void main(String[] args) throws IOException {
		mainMenu();
	}
	public static void mainMenu() throws IOException{
		System.out.println("\tMAIN MENU\n\nWelcome to storage manager!\nWhat do you want to do?\n1.Table Options\n2.Record Options\nPress any button to exit!");
		Scanner scan = new Scanner(System.in);
		String choice = scan.next();
		if(choice.equals("1")){
			tableMenu();
		}else if(choice.equals("2")){
			recordMenu();
		}else{
			System.out.println("Bye-bye!");
			return;
		}
	}
	public static void tableMenu() throws IOException{
		TableOptions tableOptions = new TableOptions();
		System.out.println("\tTABLE MENU\n\nWhat table operation do you want to do?\n1.Create a table\n2.Delete a table\n3.List all tables\nPress anything to go back to main menu");
		Scanner scan = new Scanner(System.in);
		String choice = scan.next();
		if(choice.equals("1")){
			tableOptions.addTable();
		}else if(choice.equals("2")){
			tableOptions.deleteTable();
		}else if(choice.equals("3")){
			tableOptions.listAllTables();
		}else{
			mainMenu();
			return;
		}
		System.out.println("Enter 1 to go to Table Menu!");
		System.out.println("Enter 2 to go to Main Menu!");
		System.out.println("Enter anytinhg to exit!");
		choice = scan.next();
		if(choice.equalsIgnoreCase("1"))
			tableMenu();
		else if(choice.equalsIgnoreCase("2"))
			mainMenu();
		else
			return;
	}
	public static void recordMenu() throws IOException{
		TableOptions tableOptions = new TableOptions();
		System.out.println("\tRECORD MENU\n\n1)Enter 1 to see the list of the tables\n3)Enter 2 to go enter a table name!\n3)Enter 3 to go back to main menu!\nEnter anything to exit!");
		Scanner scan = new Scanner(System.in);
		String choice = scan.next();
		if(choice.equals("1")){
			tableOptions.listAllTables();	
		}else if(choice.equalsIgnoreCase("2")){
			
		}else if(choice.equalsIgnoreCase("3")){
			mainMenu();
			return;
		}else{
			return;
		}
		RecordOptions recordOptions = new RecordOptions(tableOptions.selectATableRecord());
		subRecordMenu(recordOptions);
		
	}
	public static void subRecordMenu(RecordOptions recordOptions) throws IOException{
		Scanner scan = new Scanner(System.in);
		System.out.println("What record operation do you want to do?\n1.Insert a record\n2.Delete a record\n3.List all records\n4.Search for a record\n5.BONUS\nEnter anything to go back to main menu!");
		String choice = scan.next();
		if(choice.equalsIgnoreCase("1")){
			recordOptions.addRecord();
		}else if(choice.equalsIgnoreCase("2")){
			recordOptions.deleteARecord();
		}else if(choice.equalsIgnoreCase("3")){
			recordOptions.listAllRecords();
		}else if(choice.equalsIgnoreCase("4")){
			recordOptions.searcForARecord();
		}else if(choice.equalsIgnoreCase("5")){
			recordOptions.listAllRecordsSmallerThan();
		}else{
			mainMenu();
			return;
		}
		System.out.println("Enter 1 to go to Record Menu!");
		System.out.println("Enter 2 to go to Main Menu!");
		System.out.println("Enter anytinhg to exit!");
		choice = scan.next();
		if(choice.equalsIgnoreCase("1"))
			subRecordMenu(recordOptions);
		else if(choice.equalsIgnoreCase("2"))
			mainMenu();
		else
			System.out.println("Bye bye!");
	}
}
